(function(){
	@@include("./common/_menu.js")
	@@include("./common/_popWindow.js")
	$(".brand-detail").on("click",".fav",function(){
		if($(this).hasClass("hov")){
			$(this).removeClass("hov");
		}else{
			$(this).addClass("hov");
		}
	})
	$(".brand-detail").on("click",".products-box-tips span",function(){
		if($(this).hasClass("hov")){
			$(this).removeClass("hov");
		}else{
			$(this).addClass("hov");
		}
	})
	//搜索
	$(".search-button").click(function(){
		if($(this).hasClass("hov")){
			$(this).removeClass("hov");
			$(this).next(".search-list").hide();
		}else{
			$(this).addClass("hov");
			$(this).next(".search-list").show();
		}	
	})
	$(".search-list li").click(function(){
		var val = $(this).html();
		$(".search-button span").eq(1).html(val);
		$(".search-button").removeClass("hov");
		$(this).parent(".search-list").hide();
	})
	$(".view-more").on("click",function(){
		if($(this).hasClass("down")){
			$(".introduce").addClass("detail-ellipsis");
			$(this).removeClass("down").html("View More<i></i>");
		} else {
			$(this).addClass("down").html("Roll Up<i></i>");
			$(".introduce").removeClass("detail-ellipsis");
		}
	})
	
	var length = isMobile?40:78;
	//瀑布流
	$("img.lazy").lazyload({ 
        placeholder : "./images/images_4@2x.png",
        effect: "show",
        threshold :600
    });	
	$(".infinite-scroll").infinitescroll({
		navSelector: ".recommend-more",
		nextSelector: ".recommend-more a",
		itemSelector: ".item",
		requestUrl: "./lib/recommend.json?type=home&categor_id=1&page=",	
		loading:{
			img: "images/masonry_loading_1.gif",
			msgText: ' ',
			finishedMsg: '',
			render: function(resData,opts){
				var data = "";
				try{
	                var temp = JSON.parse(resData);
	                if(temp.code == 200) {
	                    if(opts.state.currPage >= temp.data.last_page){
	                        opts.state.isFinished = true;
	                    }
	                    $.each(temp.data.data,function(i,item){
	                    	var price = item.current_price ? item.current_price : item.original_price;
	                    	var brand = 'Brand ranking:Brand ranking:Brand ranking:Brand ranking:Brand rankingBrand rankingBrand rankingBrand ranking';
	                    	if(brand.length > length){
	                    		brand = brand.slice(0,length) + '...';
	                    	} 
	                    	data += '<div class="products-box item"><div class="products-box-img"><a href="'+item.href1+'"><span class="img-show"><img class="lazy" data-original="'+item.cover+'" alt=""></span></a></div><div class="products-box-tips"><h4><a href="'+item.href2+'" class="descrption">'+item.name+'</a><span></span></h4><div class="tips"><p><a href="1">'+ brand +'<em>NO.2</em></a></p><a href="1" class="price">'+price+'</a></div></div></div>';
	                    })
	                }
	            }catch(e){}
	            return data;
			},
			finished: function(opts){
				if(opts.state.isFinished){ //结束事件
					$(".recommend-more").remove();
					$("#infscr-loading").hide();
					$(window).unbind('.infscr');
				}
			}	
		},errorCallback:function(res){ 
			console.log(res);
		}
		
	},function(newElements){
		var $newElems = $(newElements);
		$('.infinite-scroll').append($newElems);
		$newElems.fadeIn();
		//瀑布流
		$("img.lazy").lazyload({ 
	        placeholder : "./images/images_4@2x.png",
	        effect: "show",
	        threshold :600
	    });
		return;
	});
})()